import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:get/get.dart';

import '../data/sign_status.dart';
typedef DownloadCallback = Function(bool isSuccess);
class FileManager {

  SignStatusManager signStatusManager = Get.find<SignStatusManager>();
  Future<int> saveFile(String filePath, List<int> data,{DownloadCallback? downloadCallback}) async {
    int code = 0;
    signStatusManager.updateStatus(SignStatus.startDownload);
    File savePath =
    File("${filePath.substring(0, filePath.indexOf('.'))}_sign.apk");
    if (kDebugMode) {
      print("savePath:${savePath}");
    }
    await savePath.writeAsBytes(data);
    await savePath.create();
    signStatusManager.updateStatus(SignStatus.downloadSuccess);
    downloadCallback?.call(true);
    if (kDebugMode) {
      print("文件存储成功");
    }
    code = 1;
    return Future.value(code);
  }
}
